package com.huaji.learn.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 艾宾浩斯曲线Model
 */
public class EbbinghausModel {
    /**
     * 第i天复习的列表
     */
    private List<Integer> reviewDayList;

    public EbbinghausModel() {
        reviewDayList = new ArrayList<>();
    }


    public List<Integer> getReviewDayList() {
        return reviewDayList;
    }

    public void setReviewDayList(List<Integer> reviewDayList) {
        this.reviewDayList = reviewDayList;
    }

    /**
     * 获取艾宾浩斯曲线已勾选的勾选框的字符串，用逗号分隔，数据库存储用
     * 例如： 勾选了第一天和第五天，值为 "1,5"
     * @return 选的勾选框的字符串
     */
    public String getReviewDayListStr() {
        if (reviewDayList == null || reviewDayList.stream().count() == 0){
            return "";
        }
        return  reviewDayList.stream()
                .map(Object::toString)
                .collect(Collectors.joining(", "));
    }

    /**
     * 用数据库存储的艾宾浩斯曲线的字符串赋值给当前的List
     * @param str 数据库存储的字符串
     */
    public void setReviewDayList(String str) {
        if (str == null || str.length() == 0) {
            return;
        }
        this.reviewDayList = Arrays.stream(str.split(","))
                .map(String::trim)
                .map(Integer::parseInt)
                .collect(Collectors.toList());
    }
}
